package org.ctstudio.common.bean;

import java.io.Serializable;

public abstract class IdentifiedObject implements Serializable, Comparable<IdentifiedObject> {

  private static final long serialVersionUID = -8039134966317108441L;

  private Long id;
  private byte valid = 1;

  private Integer disable;

  public interface Valid {
    // 有效的
    int YES = 0;

    // 无效的
    int NO = 1;
  }

  public static interface ValidType {
    byte INEDIT = 0;
    byte VALID = 1;
    byte INVALID = 2;
  }

  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public boolean isNew() {
    return (this.id == null);
  }

  public byte getValid() {
    return valid;
  }

  public void setValid(byte valid) {
    this.valid = valid;
  }

  @Override
  protected Object clone() throws CloneNotSupportedException {
    IdentifiedObject obj = (IdentifiedObject) super.clone();
    obj.id = this.id;
    obj.valid = this.valid;
    return obj;
  }

  public int compareTo(IdentifiedObject o) {
    return this.getId().compareTo(o.getId());
  }

  public IdentifiedObject() {
  }

  public IdentifiedObject(Long id) {
    this.setId(id);
  }

  @Override
  public int hashCode() {
    return id != null ? id.hashCode() : super.hashCode();
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (!(obj instanceof IdentifiedObject)) {
      return false;
    }

    final IdentifiedObject other = (IdentifiedObject) obj;
    assert id != null;
    assert other.id != null;

    return id.equals(other.id);
  }

  public Integer getDisable() {
    return disable;
  }

  public void setDisable(Integer disable) {
    this.disable = disable;
  }
}
